//
//  EMAInfoString.hpp
//  client
//
//  Created by galileoliu on 1/7/2019.
//
//
#ifdef USE_EMACDN

#ifndef EMAInfoString_hpp
#define EMAInfoString_hpp

#include <string>
#include "assets-manager/AssetsManagerEx.h"
#include "assets-manager/CCEventAssetsManagerEx.h"
#include "Localization.h"

using namespace cocos2d::extension;

class EMAInfoString
{
public:
    enum MessageBoxBtnType
    {
        Confirm,
        Cancel,
        Retry,
        Go,
    };
    
    std::string strUpdateInfoDefault = "hotfix_tips_default";
    std::string strUpdateInfoGettingVersion = "hotfix_tips_gettingversion";
    std::string strUpdateInfoGettingVersionSuccess = "hotfix_tips_gettingversionsuccess";
    std::string strUpdateInfoSourceDownloadList = "hotfix_tips_downloadmanifest";
    std::string strUpdateInfoSourceDownloadListSuccess = "hotfix_tips_downloadmanifestsuccessfully";
    std::string strUpdateInfoSourcePrepareUpdate = "hotfix_tips_prepareupdate";
    std::string strUpdateInfoSourceDownload = "hotfix_tips_downloading";
    std::string strUpdateInfoSourceExtract = "hotfix_tips_extracting";
    std::string strUpdateInfoNeedAppUpdate = "hotfix_tips_appupdate";
    std::string strUpdateInfoUpdateSuccessfully = "hotfix_tips_updatesuccessfully";
    
    std::string strUpdateMessageBoxBtnConfirm = "tips_ok";
    std::string strUpdateMessageBoxBtnCancel = "tips_cancel";
    std::string strUpdateMessageBoxBtnRetry = "hotfix_msgbox_retry";
    std::string strUpdateMessageBoxBtnGo = "hotfix_msgbox_gotostore";

    const std::string& GetUpdateInfoString(AssetsManagerEx::State curVersionStage)
    {
        switch (curVersionStage)
        {
            case AssetsManagerEx::State::UNCHECKED:
                return Localization::getInstance()->getStr(strUpdateInfoDefault);
            case AssetsManagerEx::State::PREDOWNLOAD_VERSION:
            case AssetsManagerEx::State::DOWNLOADING_VERSION:
                return Localization::getInstance()->getStr(strUpdateInfoGettingVersion);
            case AssetsManagerEx::State::VERSION_LOADED:
                return Localization::getInstance()->getStr(strUpdateInfoGettingVersionSuccess);
            case AssetsManagerEx::State::PREDOWNLOAD_MANIFEST:
                return Localization::getInstance()->getStr(strUpdateInfoGettingVersion);
            case AssetsManagerEx::State::DOWNLOADING_MANIFEST:
                return Localization::getInstance()->getStr(strUpdateInfoSourceDownloadList);
            case AssetsManagerEx::State::MANIFEST_LOADED:
                return Localization::getInstance()->getStr(strUpdateInfoSourceDownloadListSuccess);
            case AssetsManagerEx::State::NEED_UPDATE:
                return Localization::getInstance()->getStr(strUpdateInfoSourcePrepareUpdate);
            case AssetsManagerEx::State::UPDATING:
                return Localization::getInstance()->getStr(strUpdateInfoSourceDownload);
            case AssetsManagerEx::State::UNZIPPING:
                return Localization::getInstance()->getStr(strUpdateInfoSourceExtract);
            case AssetsManagerEx::State::NEED_APP_UPDATE:
                return Localization::getInstance()->getStr(strUpdateInfoNeedAppUpdate);
            case AssetsManagerEx::State::UP_TO_DATE:
                return Localization::getInstance()->getStr(strUpdateInfoUpdateSuccessfully);
            default:
                return Localization::getInstance()->getStr(strUpdateInfoDefault);
        }
    }
    
    const std::string& GetUpdateMsgBoxBtnString(MessageBoxBtnType type)
    {
        switch (type)
        {
            case MessageBoxBtnType::Confirm:
                return Localization::getInstance()->getStr(strUpdateMessageBoxBtnConfirm);
            case MessageBoxBtnType::Cancel:
                return Localization::getInstance()->getStr(strUpdateMessageBoxBtnCancel);
            case MessageBoxBtnType::Retry:
                return Localization::getInstance()->getStr(strUpdateMessageBoxBtnRetry);
            case MessageBoxBtnType::Go:
                return Localization::getInstance()->getStr(strUpdateMessageBoxBtnGo);
            default:
                return Localization::getInstance()->getStr(strUpdateMessageBoxBtnConfirm);
        }
    }
};


class EMAErrorString
{
public:
    std::string strUpdateErrorDefault = "hotfix_error_default";
    std::string strUpdateErrorManifestLost = "hotfix_error_manifestlost";
    std::string strUpdateErrorDownloadManifest = "hotfix_error_downloadmanifest";
    std::string strUpdateErrorParseManifest = "hotfix_error_parsemanifest";
    std::string strUpdateErrorUpdating = "hotfix_error_updating";
    std::string strUpdateErrorTimeOut = "hotfix_error_timeout";
    std::string strUpdateErrorNoSpace = "hotfix_error_nospace";
    std::string strUpdateErrorNeedAppUpdate = "hotfix_error_appupdate";
    std::string strUpdateErrorNewVersion = "hotfix_error_newversion";
    
    std::string getUpdateErrorString(EventAssetsManagerEx::EventCode code, const std::string& extraErrorMsg = "")
    {
        switch (code)
        {
            case EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND:
                return Localization::getInstance()->getStr(strUpdateErrorNewVersion) + " " + extraErrorMsg;
            case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST:
                return Localization::getInstance()->getStr(strUpdateErrorManifestLost);
            case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST:
                return Localization::getInstance()->getStr(strUpdateErrorDownloadManifest);
            case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST:
                return Localization::getInstance()->getStr(strUpdateErrorParseManifest);
            case EventAssetsManagerEx::EventCode::ERROR_UPDATING:
                return Localization::getInstance()->getStr(strUpdateErrorUpdating) + " " + extraErrorMsg;
            case EventAssetsManagerEx::EventCode::UPDATE_FAILED:
                return Localization::getInstance()->getStr(strUpdateErrorTimeOut) + " " + extraErrorMsg;
            case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS:
                return Localization::getInstance()->getStr(strUpdateErrorNoSpace);
            case EventAssetsManagerEx::EventCode::ERROR_APP_UPDATE:
                return Localization::getInstance()->getStr(strUpdateErrorNeedAppUpdate);
            default:
                return Localization::getInstance()->getStr(strUpdateErrorDefault);
        }
    }
};

#endif /* EMAInfoString_hpp */

#endif
